package com.cat.combination;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

/**
 * @author cat
 * @version 2025/5/23 17:53
 * @description 菜单类 (树枝结点)
 * @since JDK17
 */

public class Menu extends MenuComponent {
    // 菜单可以有多个子菜单或子菜单项
    private List<MenuComponent> menuComponents = new ArrayList<>();

    public Menu(String name, int level) {
        super(name, level);
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponents.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponents.remove(menuComponent);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menuComponents.get(index);
    }

    @Override
    public void print() {
        IntStream.range(1, level).forEach(o -> System.out.print("--"));
        System.out.println(name);
        menuComponents.forEach(menuComponent -> menuComponent.print());
    }
}
